package com.errol.batchprocessor.employeeaddition;

import com.renjia.entity.CoreEmployeeImportBatch;
import com.renjia.enums.BatchStatusEnum;
import com.renjia.service.CoreEmployeeImportBatchService;
import com.renjia.service.generic.log.LogService;
import com.renjia.service.generic.middleware.batchprocessor.AbstractBatchProcessorMonitorImpl;
import com.renjia.service.module.employeeaddition.advisorimpl.EmployeeAdvisorTypeEnum;
import com.renjia.service.module.employeeaddition.advisorimpl.common.payload.AbstractEmployeeBatchPayload;
import com.renjia.service.module.employeeaddition.advisorimpl.common.payload.AbstractEmployeePiecePayload;
import com.renjia.service.module.employeeaddition.advisorimpl.common.payload.AbstractEmployeeSinglePayload;
import org.springframework.stereotype.Service;

/**
 * @author zhang xiao bin
 * @version v1.0
 * @date 2021/02/22
 * @since v5.0.5
 **/
@Service
public class EmployeeMonitorServiceImpl<BE, SE, BP extends AbstractEmployeeBatchPayload<BE, SE>, PP extends AbstractEmployeePiecePayload<SE, SP>, SP extends AbstractEmployeeSinglePayload<SE>>
        extends AbstractBatchProcessorMonitorImpl<CoreEmployeeImportBatch, EmployeeAdvisorTypeEnum, BE, SE, BP, PP, SP>
        implements EmployeeMonitorService<BE, SE, BP, PP, SP> {

    private final CoreEmployeeImportBatchService coreEmployeeImportBatchService;

    public EmployeeMonitorServiceImpl(EmployeeAdditionService<BE, SE, BP, PP, SP> employeeAdditionService,
                                      LogService logService,
                                      CoreEmployeeImportBatchService coreEmployeeImportBatchService) {
        super(employeeAdditionService, logService);
        this.coreEmployeeImportBatchService = coreEmployeeImportBatchService;
    }

    @Override
    protected boolean shallAddMission(BP batchPayload) {
        return coreEmployeeImportBatchService.updateBatchStatus(batchPayload.getImportBatch(), BatchStatusEnum.UN_START, BatchStatusEnum.IN_THE_QUEUE, "");
    }

}
